<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div class="mailbox row">
	<div class="col-xs-12">
		<div class="box box-solid">
			<div class="box-body">
				<div class="row">
					<div class="col-md-3"></div>
					<div class="col-md-5">
					<!-- --------- 表单信息 start ------------- -->
						<form id="emForm" role="form" action="" method="post">
                           <div class="box-body">
                           <fieldset>
		                       <legend>基础信息</legend>
	                               <div class="form-group">
	                                   <label for="InputNr">工号</label>
	                                   <input ${onlyread==1?'disabled="disabled"':'' } name="nr" type="text" class="form-control" id="InputNr" value="${employee.nr }">
	                               </div>
	                               <div class="form-group">
	                                   <label for="InputName">姓名</label>
	                                   <input  ${onlyread==1?'disabled="disabled"':'' } name="name" type="text" class="form-control" id="InputName" value="${employee.name }">
	                               </div>
	                               <div class="form-group">
	                                   <label for="InputPassword">密码</label>
	                                   <input  ${onlyread==1?'disabled="disabled"':'' } name="password" type="${not empty id?'text':'password' }" class="form-control" id="InputPassword" value="${employee.password }">
	                               </div>
	                               <div class="form-group">
	                                   <label for="InputDepartment">部门</label>
	                                   <select  ${onlyread==1?'disabled="disabled"':'' } name="department.id" id="InputDepartment">
	                                   		<c:forEach var="dept" items="${departmentList}">
	                                   			<c:if test="${dept.id==employee.department.id}">
		                                   			<option selected="selected" value="${dept.id}">${dept.name}</option>	
	                                   			</c:if>
	                                   			<c:if test="${dept.id!=employee.department.id}">
	                                   				<option value="${dept.id}">${dept.name}</option>
	                                   			</c:if>
	                                   		</c:forEach>
	                                   </select>
	                               </div>
	                               
	                               <div class="form-group">
	                                   <label for="InputGender">性别</label>
	                                   <select  ${onlyread==1?'disabled="disabled"':'' } name="gender" id="InputGender">
	                                   		<c:choose>
	                                   			<c:when test="${employee.id>0 }">
		                                   			<c:if test="${employee.gender==false}">
				                                   		<option selected="selected" value="0">女</option>
				                                   		<option value="1">男</option>
		                                   			</c:if>
		                                   			<c:if test="${employee.gender==true}">
			                                  			<option value="0">女</option>
			                                   			<option  selected="selected" value="1">男</option>
		                                   			</c:if>
	                                   			</c:when>
	                                   			<c:otherwise>
	                                   				<option value="0">女</option>
		                                   			<option  selected="selected" value="1">男</option>
	                                   			</c:otherwise>
	                                   		</c:choose>
	                                   </select>
	                               </div>
	                               <input id="empId" name="id" type="hidden" value="${employee.id }"/><!-- 用于编辑 -->
	                               <input name="isManager" type="hidden" value="${employee.isManager }"/><!-- 用于编辑 -->
	                               <input name="status" type="hidden" value="${employee.status }"/><!-- 用于编辑 -->
                               </fieldset>
                               <!-- 授权 员工配角色 -->
                            <fieldset>
                             	<legend>授权</legend>
                             	<!-- hashmap -->
                             	<c:forEach var="map" items="${allRoleMap}" begin="0" step="1"  varStatus="vs">
	                            	<c:if test="${map.value==true}">
	                            		<div class="form-group" style="margin-left: 10px;display: inline" >
								   			<label>${map.key.name}</label>
								   			<input checked="checked" name="roles[${vs.index}].id" type="checkbox" class="form-control" value="${map.key.id}" ${onlyread==1?'disabled="disabled"':'' }>
								 		</div>
	                            	</c:if>
	                            	<c:if test="${map.value==false}">
	                            		<div class="form-group" style="margin-left: 10px;display: inline" >
								   			<label>${map.key.name}</label>
								   			<input name="roles[${vs.index}].id" type="checkbox" class="form-control" value="${map.key.id}" ${onlyread==1?'disabled="disabled"':'' }>
								 		</div>
	                            	</c:if>
		                        </c:forEach>
                            </fieldset>
                           </div>
							<!-- ---------id  和  isManager 和  Status 在编辑时加载  才赋值 ------------- -->
                           <div class="box-footer">
                           		<c:if test="${onlyread==0 }">
                               		<button id="subBtn" type="button" class="btn btn-primary">保存</button>
                               </c:if>
                           </div>
                       </form>
                       <script type="text/javascript">
                       		$(function(){
                       			$("#subBtn").click(function(){
                       				if($("#empId").val()>0){
                       					$("form").attr("action","${initParam.root}/employee-edit");
                     				}else{
                     					$("form").attr("action","${initParam.root}/employee-add");
                     				}
                     				$("#emForm").submit();
                       			});
                       		})
                       </script>
                       <!-- --------- 表单信息 end ------------- -->
					</div>
					<div class="col-md-3"></div>
				</div>
				<!-- /.row -->
			</div>
		</div>
		<!-- /.box -->
	</div>
	<!-- /.col (MAIN) -->
</div>
<!-- MAILBOX END -->